package org.linlinjava.litemall.admin.web2.auth.req;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
import org.linlinjava.litemall.db.domain.LitemallAdmin;
import org.linlinjava.litemall.db.util.Str;

@ApiModel
public class AReq {
    @ApiModelProperty("id")
    private Integer id;
    @ApiModelProperty("登录账号[无法编辑]")
    private String username;
    @ApiModelProperty("登录密码")
    private String password;
    @ApiModelProperty("真实名字")
    private String realName;
    @ApiModelProperty("微信")
    private String wx;
    @ApiModelProperty("联系电话")
    private String phone;
    @ApiModelProperty("商铺id")
    private Integer shopId;
    @ApiModelProperty("商品管理员")
    private Boolean goodsManager;
    @ApiModelProperty("商品派送员")
    private Boolean sendManager;
    @ApiModelProperty("锁定")
    private Boolean lock;


    public static LitemallAdmin getEntity(AReq req) {
        LitemallAdmin admin = new LitemallAdmin();
        admin.setUsername(req.username);
        //设置密码
        String rawPassword = req.getPassword();
        if (!Str.isEmpty(rawPassword)) {
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            String encodedPassword = encoder.encode(rawPassword);
            admin.setPassword(encodedPassword);
        }


        admin.setDeleted(Boolean.FALSE);
        admin.setGoodsManager(req.goodsManager);
        admin.setSendManager(req.sendManager);
        admin.setLock(req.lock);
        admin.setPhone(req.phone);
        admin.setRealName(req.realName);
        admin.setWx(req.wx);
        admin.setShopId(req.shopId);


        if (admin.getGoodsManager() == null)
            admin.setGoodsManager(Boolean.FALSE);

        if (admin.getSendManager() == null)
            admin.setSendManager(Boolean.FALSE);

        if (admin.getLock() == null)
            admin.setLock(Boolean.FALSE);

        return admin;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }


    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getWx() {
        return wx;
    }

    public void setWx(String wx) {
        this.wx = wx;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Integer getShopId() {
        return shopId;
    }

    public void setShopId(Integer shopId) {
        this.shopId = shopId;
    }

    public Boolean getGoodsManager() {
        return goodsManager;
    }

    public void setGoodsManager(Boolean goodsManager) {
        this.goodsManager = goodsManager;
    }

    public Boolean getSendManager() {
        return sendManager;
    }

    public void setSendManager(Boolean sendManager) {
        this.sendManager = sendManager;
    }

    public Boolean getLock() {
        return lock;
    }

    public void setLock(Boolean lock) {
        this.lock = lock;
    }
}
